board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
# board=[["O","O","O","O","X","X"],["O","O","O","O","O","O"],["O","X","O","X","O","O"],["O","X","O","O","X","O"],["O","X","O","X","O","O"],["O","X","O","O","O","O"]]
print(board)
direction=[-1,0,1,0,-1]

def dfs(board,i,j):
    if i<0 or j<0 or i>=len(board) or j>=len(board[0]) or board[i][j]=='X' or board[i][j]=='#':
        return None
    board[i][j]="#"
    dfs(board,i-1,j)
    dfs(board,i+1,j)
    dfs(board,i,j-1)
    dfs(board,i,j+1)

def solve(board):
    if board==None or len(board)==0:
        return None
    m,n=len(board),len(board[0])
    for i in range(m):
        for j in range(n):
            #从边缘O开始搜索
            isEdge=(i==0) or (j==0) or(i==m-1) or (j==n-1)
            if isEdge and board[i][j]=='O':
                dfs(board,i,j)
    for i in range(m):
        for j in range(n):
            if board[i][j]=='O':
                board[i][j]='X'
            if board[i][j]=='#':
                board[i][j]='O'
    return board
print(solve(board))